home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_03 / kamradt / lowlev.txt < prev    next >
Text File  |  1994-02-07  |  563b  |  20 lines

  1. Figure 10a. Results of an inefficient += operator.
  2.  
  3.  1.0235   500  void PadWithSpaces(CString &str, int count)
  4.               {
  5.  5.0346 20000    while(count--)
  6. 30.0397 19000      str += " ";
  7.  1.4354   500  }
  8.  
  9. Figure 10b. Improved performance with low-level C-strings.
  10.  
  11.  1.0233   500  void PadWithSpaces(CString &str, int count)
  12.               {
  13.  2.4505   500   char *tmp = new char[count+1];
  14.  3.2930   500    memset(tmp,' ',count);
  15.  0.9438   500    tmp[count] = '\0';
  16.  5.3049   500    str += tmp;
  17.  1.9430   500    delete[] tmp;
  18.  1.4353   500  }
  19.  
  20.